tools: sunxi: avoid read after end of string
author[email protected] <[email protected]>
Thu, 4 May 2017 20:26:42 +0000 (22:26 +0200)
committerTom Rini <[email protected]>
Fri, 5 May 2017 20:45:57 +0000 (16:45 -0400)
The evaluation of option -c is incorrect:

According to the C99 standard endptr in the first strtol is always
set as &endptr is not NULL.
So the first part of the or condition is always true.
If all digits in optarg are valid endptr will point to the closing \0
and the second strtol will read beyond the end of the string optarg
points to.

Signed-off-by: Heinrich Schuchardt <[email protected]>
Acked-by: Boris Brezillon <[email protected]>
tools/sunxi-spl-image-builder.c

index d538a38813194a0e88df97f6f281c34ebada7636..a367f117740386c3d37028ad93f2b725caa9420a 100644 (file)
@@ -433,7 +433,7 @@ int main(int argc, char **argv)
                        break;
                case 'c':
                        info.ecc_strength = strtol(optarg, &endptr, 0);
-                       if (endptr || *endptr == '/')
+                       if (*endptr == '/')
                                info.ecc_step_size = strtol(endptr + 1, NULL, 0);
                        break;
                case 'p':